package com.kolaxy.mqdemo;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <一句话功能描述><功能详细描述>
 *
 * @author zhourunjin
 * @version: [版本号，2018-09-14]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
@RestController
public class MqController {

    private static Logger logger = LoggerFactory.getLogger(MqController.class);

    private static final  String prex = "mq";

    @Autowired
    private Environment environment;

    @Autowired
    private AmqpTemplate template;

    @RequestMapping("/send/rec")
    public String sendAndRec(String message){
        if (StringUtils.isEmpty(message)){
            message = environment.getProperty("mq.first.message");
        }

        template.convertAndSend(environment.getProperty("mq.first.queue"),message);

        return "ok";
    }
}
